<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>银行账户密码重置</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background-image: url("../R-C.jpg");
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 500px;
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 12px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
            overflow: hidden;
            animation: fadeIn 0.8s ease-out;
        }

        .header {
            background: linear-gradient(to right, #1a3a6c, #2c5a8d);
            color: white;
            padding: 30px;
            text-align: center;
            position: relative;
        }

        .header::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(to right, #ffcc00, #ff9900);
        }

        .header h1 {
            font-size: 28px;
            margin-bottom: 15px;
            font-weight: 600;
            letter-spacing: 0.5px;
        }

        .header p {
            font-size: 16px;
            opacity: 0.9;
            max-width: 400px;
            margin: 0 auto;
        }

        .header i {
            font-size: 60px;
            margin-bottom: 20px;
            color: #ffcc00;
            filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.3));
        }

        .form-container {
            padding: 35px;
        }

        .step-indicator {
            display: flex;
            justify-content: space-between;
            margin-bottom: 40px;
            position: relative;
        }

        .step-indicator::before {
            content: '';
            position: absolute;
            top: 20px;
            left: 0;
            right: 0;
            height: 3px;
            background-color: #f0f0f0;
            z-index: 1;
            border-radius: 2px;
        }

        .step {
            text-align: center;
            z-index: 2;
            position: relative;
        }

        .step-icon {
            width: 40px;
            height: 40px;
            background-color: #e0e0e0;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 10px;
            font-weight: bold;
            color: #888;
            font-size: 16px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }

        .step.active .step-icon {
            background-color: #1a3a6c;
            color: white;
            transform: scale(1.1);
            box-shadow: 0 3px 8px rgba(26, 58, 108, 0.4);
        }

        .step.completed .step-icon {
            background-color: #2ecc71;
            color: white;
            box-shadow: 0 3px 8px rgba(46, 204, 113, 0.4);
        }

        .step-text {
            font-size: 13px;
            color: #777;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .step.active .step-text {
            color: #1a3a6c;
            font-weight: 600;
            text-shadow: 0 0 1px rgba(26, 58, 108, 0.3);
        }

        .step-form {
            display: none;
            opacity: 0;
            transform: translateY(10px);
            transition: all 0.4s ease;
        }

        .step-form.active {
            display: block;
            opacity: 1;
            transform: translateY(0);
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #444;
            font-size: 15px;
        }

        .form-group input {
            width: 100%;
            padding: 14px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
            background-color: #f9f9f9;
        }

        .form-group input:focus {
            border-color: #1a3a6c;
            box-shadow: 0 0 0 3px rgba(26, 58, 108, 0.15);
            outline: none;
            background-color: white;
        }

        .input-with-icon i {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #888;
        }

        .btn-group {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }

        .btn {
            padding: 14px;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            flex: 1;
            text-align: center;
            border: none;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .btn i {
            margin-right: 8px;
        }

        .btn-next {
            background-color: #1a3a6c;
            color: white;
        }

        .btn-next:hover {
            background-color: #15315a;
            transform: translateY(-3px);
            box-shadow: 0 7px 15px rgba(26, 58, 108, 0.25);
        }

        .btn-back {
            background-color: #f0f0f0;
            color: #444;
        }

        .btn-back:hover {
            background-color: #e0e0e0;
            transform: translateY(-3px);
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }

        .btn-submit {
            background-color: #2ecc71;
            color: white;
            width: 100%;
        }

        .btn-submit:hover {
            background-color: #27ae60;
            transform: translateY(-3px);
            box-shadow: 0 7px 15px rgba(46, 204, 113, 0.35);
        }

        .security-info {
            display: flex;
            align-items: center;
            background-color: #f8f9fc;
            border-radius: 8px;
            padding: 15px;
            margin-top: 25px;
            border-left: 4px solid #4CAF50;
        }

        .security-info i {
            font-size: 24px;
            color: #4CAF50;
            margin-right: 15px;
        }

        .security-text {
            font-size: 13px;
            color: #555;
            line-height: 1.5;
        }

        .password-inputs {
            display: flex;
            justify-content: space-between;
            gap: 10px;
            margin-bottom: 15px;
        }

        .password-input {
            width: 50px;
            height: 60px;
            text-align: center;
            font-size: 24px;
            font-weight: bold;
            border: 2px solid #ddd;
            border-radius: 8px;
            transition: all 0.3s;
            background-color: #f5f8fa;
        }

        .password-input:focus {
            border-color: #1a3a6c;
            box-shadow: 0 0 0 3px rgba(26, 58, 108, 0.15);
            outline: none;
        }

        .password-input.filled {
            background-color: #e3f2fd;
            border-color: #1a3a6c;
        }

        .password-hint {
            text-align: center;
            font-size: 14px;
            color: #666;
            margin-top: 15px;
        }

        .error-message {
            color: #e74c3c;
            font-size: 13px;
            margin-top: 8px;
            display: none;
            text-align: center;
            background-color: rgba(231, 76, 60, 0.08);
            padding: 8px;
            border-radius: 6px;
        }

        .success-message {
            text-align: center;
            padding: 30px;
            display: none;
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.5s ease;
        }

        .success-message.active {
            display: block;
            opacity: 1;
            transform: translateY(0);
        }

        .success-message i {
            font-size: 70px;
            color: #2ecc71;
            margin-bottom: 20px;
            animation: zoomIn 0.5s ease forwards;
        }

        .success-message h2 {
            color: #1a3a6c;
            margin-bottom: 15px;
            font-size: 26px;
        }

        .success-message p {
            color: #444;
            margin-bottom: 25px;
            line-height: 1.6;
            font-size: 16px;
        }

        .btn-login {
            background-color: #1a3a6c;
            color: white;
            display: inline-block;
            padding: 12px 30px;
            border-radius: 8px;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s;
            box-shadow: 0 4px 10px rgba(26, 58, 108, 0.3);
        }

        .btn-login:hover {
            background-color: #15315a;
            transform: translateY(-3px);
            box-shadow: 0 7px 15px rgba(26, 58, 108, 0.4);
        }

        .api-status {
            margin-top: 15px;
            padding: 12px;
            border-radius: 8px;
            font-size: 14px;
            text-align: center;
            display: none;
        }

        .api-status.loading {
            display: block;
            background-color: rgba(52, 152, 219, 0.15);
            color: #1a3a6c;
        }

        .api-status.error {
            display: block;
            background-color: rgba(231, 76, 60, 0.15);
            color: #e74c3c;
        }

        .api-status.success {
            display: block;
            background-color: rgba(46, 204, 113, 0.15);
            color: #27ae60;
        }

        .bank-logo {
            position: absolute;
            top: 15px;
            left: 20px;
            font-size: 24px;
            font-weight: bold;
            color: #ffcc00;
            display: flex;
            align-items: center;
        }

        .bank-logo i {
            margin-right: 10px;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes zoomIn {
            from { transform: scale(0.5); opacity: 0; }
            to { transform: scale(1); opacity: 1; }
        }

        @media (max-width: 576px) {
            .container {
                max-width: 100%;
            }

            .form-container {
                padding: 25px 20px;
            }

            .header {
                padding: 25px 20px;
            }

            .header h1 {
                font-size: 24px;
            }

            .header i {
                font-size: 50px;
            }

            .form-group input {
                padding: 12px 15px;
            }

            .step-text {
                font-size: 12px;
            }

            .btn-group {
                flex-direction: column;
                gap: 10px;
            }

            .password-input {
                width: 40px;
                height: 50px;
                font-size: 22px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="bank-logo">
                <i class="fas fa-university"></i>
            </div>
            <i class="fas fa-lock"></i>
            <h1>银行账户密码重置</h1>
            <p>请按照以下步骤重新设置您的账户密码</p>
        </div>

        <div class="form-container">
            <!-- 步骤指示器 -->
            <div class="step-indicator">
                <div class="step active" id="step1">
                    <div class="step-icon">1</div>
                    <div class="step-text">身份验证</div>
                </div>
                <div class="step" id="step2">
                    <div class="step-icon">2</div>
                    <div class="step-text">设置密码</div>
                </div>
                <div class="step" id="step3">
                    <div class="step-icon">3</div>
                    <div class="step-text">完成</div>
                </div>
            </div>

            <!-- 步骤1：身份验证 -->
            <div class="step-form active" id="form-step1">
                <div class="form-group">
                    <label for="cardID">银行卡号 <span class="required">*</span></label>
                    <input type="text" id="cardID" placeholder="请输入您的银行卡号">
                    <div class="error-message" id="cardIDError">请输入有效的银行卡号</div>
                </div>

                <div class="form-group">
                    <label for="telephone">手机号 <span class="required">*</span></label>
                    <input type="text" id="telephone" placeholder="请输入您的手机号码" maxlength="11">
                    <div class="error-message" id="telephoneError">请输入有效的手机号</div>
                </div>

                <div class="security-info">
                    <i class="fas fa-shield-alt"></i>
                    <div class="security-text">系统将验证您提供的银行卡号和手机号。所有信息都将进行加密处理，确保安全。</div>
                </div>

                <div class="btn-group">
                    <button class="btn btn-back" id="btn-cancel">
                        <i class="fas fa-times"></i> 取消
                    </button>
                    <button class="btn btn-next" id="btn-step1-next">
                        <i class="fas fa-arrow-right"></i> 下一步
                    </button>
                </div>
            </div>

            <!-- 步骤2：设置密码 -->
            <div class="step-form" id="form-step2">
                <div class="form-group">
                    <label>设置6位数字密码 <span class="required">*</span></label>
                    <div class="password-inputs">
                        <input type="text" class="password-input" id="p1" maxlength="1" data-index="1" inputmode="numeric">
                        <input type="text" class="password-input" id="p2" maxlength="1" data-index="2" inputmode="numeric">
                        <input type="text" class="password-input" id="p3" maxlength="1" data-index="3" inputmode="numeric">
                        <input type="text" class="password-input" id="p4" maxlength="1" data-index="4" inputmode="numeric">
                        <input type="text" class="password-input" id="p5" maxlength="1" data-index="5" inputmode="numeric">
                        <input type="text" class="password-input" id="p6" maxlength="1" data-index="6" inputmode="numeric">
                    </div>
                    <div class="error-message" id="passwordError">请输入6位数字密码</div>

                    <div class="password-hint">
                        <i class="fas fa-info-circle"></i> 新密码必须为6位数字，不含字母或特殊字符
                    </div>
                </div>

                <div class="form-group">
                    <label>确认6位数字密码 <span class="required">*</span></label>
                    <div class="password-inputs">
                        <input type="text" class="password-input" id="c1" maxlength="1" data-index="1" inputmode="numeric">
                        <input type="text" class="password-input" id="c2" maxlength="1" data-index="2" inputmode="numeric">
                        <input type="text" class="password-input" id="c3" maxlength="1" data-index="3" inputmode="numeric">
                        <input type="text" class="password-input" id="c4" maxlength="1" data-index="4" inputmode="numeric">
                        <input type="text" class="password-input" id="c5" maxlength="1" data-index="5" inputmode="numeric">
                        <input type="text" class="password-input" id="c6" maxlength="1" data-index="6" inputmode="numeric">
                    </div>
                    <div class="error-message" id="confirmError">两次输入的密码不一致</div>
                </div>

                <div class="btn-group">
                    <button class="btn btn-back" id="btn-back-to-step1">
                        <i class="fas fa-arrow-left"></i> 上一步
                    </button>
                    <button class="btn btn-submit" id="btn-submit">
                        <i class="fas fa-check"></i> 提交
                    </button>
                </div>

                <div class="api-status" id="apiStatus"></div>
            </div>

            <!-- 步骤3：完成 -->
            <div class="success-message" id="form-step3">
                <i class="fas fa-check-circle"></i>
                <h2>密码重置成功！</h2>
                <p>您的银行账户密码已成功更新。新密码将立即生效，建议您定期更换密码以保证账户安全。</p>
                <a href="../login.html" class="btn-login">
                    <i class="fas fa-sign-in-alt"></i> 立即登录
                </a>
            </div>
        </div>
    </div>

    <script>
        // 当前步骤
        let currentStep = 1;
        const step1 = document.getElementById('form-step1');
        const step2 = document.getElementById('form-step2');
        const step3 = document.getElementById('form-step3');
        const apiStatus = document.getElementById('apiStatus');

        // 步骤指示器
        const stepIndicator1 = document.getElementById('step1');
        const stepIndicator2 = document.getElementById('step2');
        const stepIndicator3 = document.getElementById('step3');

        // 下一步按钮 - 步骤1
        document.getElementById('btn-step1-next').addEventListener('click', function() {
            const cardID = document.getElementById('cardID').value.trim();
            const telephone = document.getElementById('telephone').value.trim();
            let isValid = true;

            // 验证银行卡号
            if (!validateCardID(cardID)) {
                showError('cardIDError', '银行卡号应为16-19位数字');
                document.getElementById('cardID').classList.add('input-error');
                isValid = false;
            } else {
                hideError('cardIDError');
                document.getElementById('cardID').classList.remove('input-error');
            }

            // 验证手机号
            if (!validateTelephone(telephone)) {
                showError('telephoneError', '请输入有效的11位手机号');
                document.getElementById('telephone').classList.add('input-error');
                isValid = false;
            } else {
                hideError('telephoneError');
                document.getElementById('telephone').classList.remove('input-error');
            }

            if (isValid) {
                // 切换到步骤2
                step1.classList.remove('active');
                step2.classList.add('active');

                // 更新步骤指示器
                stepIndicator1.classList.remove('active');
                stepIndicator1.classList.add('completed');
                stepIndicator2.classList.add('active');

                currentStep = 2;

                // 自动聚焦到第一个密码输入框
                document.getElementById('p1').focus();
            }
        });

        // 上一步按钮 - 步骤2
        document.getElementById('btn-back-to-step1').addEventListener('click', function() {
            // 切换到步骤1
            step2.classList.remove('active');
            step1.classList.add('active');

            // 更新步骤指示器
            stepIndicator2.classList.remove('active');
            stepIndicator1.classList.remove('completed');
            stepIndicator1.classList.add('active');

            currentStep = 1;
        });

        // 提交按钮 - 步骤2
        document.getElementById('btn-submit').addEventListener('click', function() {
            const cardID = document.getElementById('cardID').value.trim();
            const telephone = document.getElementById('telephone').value.trim();
            const password = getPassword();
            const confirmPassword = getConfirmPassword();
            let isValid = true;

            // 验证密码
            if (!validatePassword(password)) {
                showError('passwordError', '请输入6位数字密码');
                markPasswordError();
                isValid = false;
            } else {
                hideError('passwordError');
                unmarkPasswordError();
            }

            // 验证确认密码
            if (password !== confirmPassword) {
                showError('confirmError', '两次输入的密码不一致');
                markConfirmPasswordError();
                isValid = false;
            } else {
                hideError('confirmError');
                unmarkConfirmPasswordError();
            }

            if (isValid) {
                // 检查密码安全性
                if (isWeakPassword(password)) {
                    if (!confirm('您设置的密码安全性较低（简单重复或连续数字），确定要继续吗？')) {
                        return;
                    }
                }

                // 显示加载状态
                showApiStatus('正在提交，请稍候...', 'loading');

                // 模拟API调用
                setTimeout(function() {
                    // 这里在实际应用中应该调用真实API
                    callUpdatePasswordAPI(cardID, telephone, password);
                }, 1200);
            }
        });

        // 模拟API调用
        function callUpdatePasswordAPI(cardID, telephone, newPassword) {
            // 构造API URL，包含查询参数
            const apiUrl = `http://localhost:8080/customer/updatePassword?cardID=${encodeURIComponent(cardID)}&telephone=${encodeURIComponent(telephone)}&newPassword=${encodeURIComponent(newPassword)}`;

            // 显示加载状态
            showApiStatus('正在提交，请稍候...', 'loading');

            // 使用fetch API调用真实接口
            fetch(apiUrl, {
                method: 'PUT',
                headers: {
                    'Content-Type': 'application/json',
                    'Accept': 'application/json'
                }
            })
            .then(response => {
                if (response.ok) {
                    return response.json();
                } else {
                    throw new Error('API请求失败，状态码：' + response.status);
                }
            })
            .then(data => {
                // 检查API返回的业务逻辑状态
                if (data.code === '200' || data.code === '0') {
                    // 切换到完成步骤
                    step2.classList.remove('active');
                    step3.classList.add('active');

                    // 更新步骤指示器
                    stepIndicator2.classList.remove('active');
                    stepIndicator2.classList.add('completed');
                    stepIndicator3.classList.add('active');

                    // 显示成功消息
                    showApiStatus('<i class="fas fa-check-circle"></i> ' + (data.message || '密码重置成功！'), 'success');
                } else {
                    // API返回业务错误
                    showApiStatus('<i class="fas fa-exclamation-triangle"></i> ' + (data.message || '操作失败：未知错误'), 'error');
                }
            })
            .catch(error => {
                // 处理错误情况
                if (error.name === 'TypeError') {
                    errorMsg = '网络连接异常，请检查您的网络设置';
                } else {
                    errorMsg = error.message || error;
                }

                showApiStatus('<i class="fas fa-exclamation-triangle"></i> ' + errorMsg, 'error');
            });
        }

        // 取消按钮
        document.getElementById('btn-cancel').addEventListener('click', function() {
            if (confirm('确定要取消密码重置吗？所有输入的信息将会丢失。')) {
                window.location.href = '../login.html';
            }
        });

        // 获取密码值
        function getPassword() {
            return document.getElementById('p1').value +
                   document.getElementById('p2').value +
                   document.getElementById('p3').value +
                   document.getElementById('p4').value +
                   document.getElementById('p5').value +
                   document.getElementById('p6').value;
        }

        // 获取确认密码值
        function getConfirmPassword() {
            return document.getElementById('c1').value +
                   document.getElementById('c2').value +
                   document.getElementById('c3').value +
                   document.getElementById('c4').value +
                   document.getElementById('c5').value +
                   document.getElementById('c6').value;
        }

        // 验证函数
        function validateCardID(cardID) {
            // 基本验证：16-19位数字
            return /^\d{16,19}$/.test(cardID);
        }

        function validateTelephone(telephone) {
            // 基本验证：11位数字
            return /^\d{11}$/.test(telephone);
        }

        function validatePassword(password) {
            // 必须是6位数字
            return /^\d{6}$/.test(password);
        }

        function showError(elementId, message) {
            const errorElement = document.getElementById(elementId);
            errorElement.textContent = message;
            errorElement.style.display = 'block';
        }

        function hideError(elementId) {
            document.getElementById(elementId).style.display = 'none';
        }

        function markPasswordError() {
            const inputs = document.querySelectorAll('#p1, #p2, #p3, #p4, #p5, #p6');
            inputs.forEach(input => {
                input.classList.add('input-error');
            });
        }

        function unmarkPasswordError() {
            const inputs = document.querySelectorAll('#p1, #p2, #p3, #p4, #p5, #p6');
            inputs.forEach(input => {
                input.classList.remove('input-error');
            });
        }

        function markConfirmPasswordError() {
            const inputs = document.querySelectorAll('#c1, #c2, #c3, #c4, #c5, #c6');
            inputs.forEach(input => {
                input.classList.add('input-error');
            });
        }

        function unmarkConfirmPasswordError() {
            const inputs = document.querySelectorAll('#c1, #c2, #c3, #c4, #c5, #c6');
            inputs.forEach(input => {
                input.classList.remove('input-error');
            });
        }

        function showApiStatus(message, status) {
            apiStatus.textContent = message;
            apiStatus.className = 'api-status';
            if (status) {
                apiStatus.classList.add(status);
            }
        }

        // 银行卡号输入格式限制
        document.getElementById('cardID').addEventListener('input', function() {
            let value = this.value.trim();
            value = value.replace(/\D/g, '');
            if (value.length > 19) {
                value = value.substring(0, 19);
            }
            this.value = value;
        });

        // 手机号输入格式限制
        document.getElementById('telephone').addEventListener('input', function() {
            let value = this.value.trim();
            value = value.replace(/\D/g, '');
            if (value.length > 11) {
                value = value.substring(0, 11);
            }
            this.value = value;
        });

        // 密码输入框处理
        const passwordInputs = document.querySelectorAll('.password-input');
        passwordInputs.forEach(input => {
            // 限制输入数字
            input.addEventListener('input', function() {
                this.value = this.value.replace(/\D/g, '');

                // 自动前进到下一个输入框
                if (this.value.length === 1) {
                    const nextIndex = parseInt(this.dataset.index) + 1;
                    const nextInput = this.parentElement.querySelector(`.password-input[data-index="${nextIndex}"]`);
                    if (nextInput) {
                        nextInput.focus();
                    }

                    // 添加填充样式
                    this.classList.add('filled');
                } else if (this.value.length === 0) {
                    this.classList.remove('filled');
                }
            });

            // 处理退格键
            input.addEventListener('keydown', function(e) {
                if (e.key === 'Backspace' && this.value.length === 0) {
                    const prevIndex = parseInt(this.dataset.index) - 1;
                    const prevInput = this.parentElement.querySelector(`.password-input[data-index="${prevIndex}"]`);
                    if (prevInput) {
                        prevInput.focus();
                        prevInput.value = '';
                        prevInput.classList.remove('filled');
                    }
                }
            });
        });
    </script>
</body>
</html>